package com.sq.universe.flowable.service.impl;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
import org.flowable.common.engine.api.delegate.event.FlowableEvent;
import org.flowable.common.engine.api.delegate.event.FlowableEventListener;
import org.flowable.common.engine.api.delegate.event.FlowableEventType;
import org.flowable.task.service.impl.persistence.entity.TaskEntityImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.flowable.engine.*;

@Component
@Slf4j
public class FlowableBaseEventListenerImpl  implements FlowableEventListener {


    @Autowired
    private TaskService taskService;

    @Override
    public void onEvent(FlowableEvent flowableEvent) {
        FlowableEventType type = flowableEvent.getType();

        if (type == FlowableEngineEventType.TASK_CREATED){

        }
        else if (type == FlowableEngineEventType.TASK_COMPLETED || type == FlowableEngineEventType.ACTIVITY_CANCELLED) {
            // 用户审批任务
            if (flowableEvent instanceof org.flowable.engine.delegate.event.impl.FlowableEntityWithVariablesEventImpl) {
                org.flowable.engine.delegate.event.impl.FlowableEntityWithVariablesEventImpl eventImpl = (org.flowable.engine.delegate.event.impl.FlowableEntityWithVariablesEventImpl) flowableEvent;
                TaskEntityImpl taskEntity = (TaskEntityImpl) eventImpl.getEntity();
            }
        }
    }

    @Override
    public boolean isFailOnException() {
        return false;
    }

    @Override
    public boolean isFireOnTransactionLifecycleEvent() {
        return false;
    }

    @Override
    public String getOnTransaction() {
        return null;
    }
}
